home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / viper.info-2 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  35.4 KB  |  829 lines

  1. This is Info file ../info/viper.info, produced by Makeinfo-1.63 from
  2. the input file viper.texi.
  3.  
  4. Distribution
  5. ************
  6.  
  7. Copyright (C) 1991 Aamod Sane
  8. Copyright (C) 1994 Michael Kifer
  9.  
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided that
  16. the entire resulting derived work is distributed under the terms of a
  17. permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the same conditions as for modified
  21. versions.
  22.  
  23. 
  24. File: viper.info,  Node: New Commands,  Next: Useful Packages,  Prev: Movement and Markers,  Up: Improvements over Vi
  25.  
  26. New Commands
  27. ============
  28.  
  29.    These commands have no Vi analogs.
  30.  
  31. `C-x, C-c'
  32.      `C-x' will exit from Vi state and return to Emacs state
  33.      *temporarily*. If you hit one of these keys, Emacs will believe
  34.      that you hit that key in Emacs state. For example, if you hit `C-x'
  35.      followed by `2', then the current window will be split into 2 and
  36.      you will be in Vi state again. Except for novice users, `C-c' is
  37.      also set to temporarily escape to Emacs and execute a command from
  38.      the current major mode.  `ESC' will do the same, if you configure
  39.      ESC as Meta by setting `vip-no-multiple-ESC' to nil in `.vip'.
  40.      *Note Customization::. `C-z' in Insert state will make Emacs think
  41.      `Meta' has been hit.
  42.  
  43. `\'
  44.      Escape to Emacs to execute a single Emacs command. For instance, `\
  45.      ESC' will act like a Meta key.
  46.  
  47. `Q'
  48.      `Q' is for query replace.  By default, each string to be replaced
  49.      is treated as a regular expression. You can use `(setq
  50.      vip-re-query-replace nil)' in your `.emacs' file to turn this off.
  51.      (For normal searches, `:se nomagic' will work. Note that `:se
  52.      nomagic' turns Regexps off completely, unlike Vi).
  53.  
  54. `v'
  55. `V'
  56. `C-v'
  57.      These keys are used to visit files.  `v' will switch to a buffer
  58.      visiting file whose name can be entered in the Minibuffer. `V' is
  59.      similar, but will use a window different from the current window.
  60.      `C-v' is like `V', except that a new frame (X window) will be used
  61.      instead of a new Emacs window.
  62.  
  63. `#'
  64.      If followed by a certain character CH, it becomes an operator whose
  65.      argument is the region determined by the motion command that
  66.      follows (indicated as <move>).  Currently, CH can be one of `c',
  67.      `C', `g', `q', and `s'. For instance, `#qr' will prompt you for a
  68.      string and then prepend this string to each line in the buffer.
  69.  
  70. `# c'
  71.      Change upper case characters in the region to lower case
  72.      (`downcase-region').  Emacs command `M-l' does the same for words.
  73.  
  74. `# C'
  75.      Change lower case characters in the region to upper case. For
  76.      instance, `# C 3 w' will capitalize 3 words from the current point
  77.      (`upcase-region').  Emacs command `M-l' does the same for words.
  78.  
  79. `# g'
  80.      Execute last keyboard macro for each line in the region
  81.      (`vip-global-execute').
  82.  
  83. `# q'
  84.      Insert specified string at the beginning of each line in the region
  85.      (`vip-quote-region').
  86.  
  87. `# s'
  88.      Check spelling of words in the region (`spell-region').  The
  89.      function used for spelling is determined from the variable
  90.      `vip-spell-function'.
  91.  
  92. `*'
  93.      Call last keyboard macro.
  94.  
  95. `m .'
  96.      Set mark at point and push old mark off the ring
  97.  
  98. `m<'
  99. `m>'
  100.      Set mark at beginning and end of buffer, respectively.
  101.  
  102. `m,'
  103.      Jump to mark and pop mark off the ring. *Note Mark: (emacs)Mark,
  104.      for more info.
  105.  
  106. `] register'
  107.      View contents of register
  108.  
  109. `[ textmarker'
  110.      View filename and position of textmarker
  111.  
  112. `@#'
  113. `@register'
  114. `@!'
  115.      Begin/end keyboard macro. @register has a different meaning when
  116.      used after a `@#'. *Note Macros and Registers::, for details
  117.  
  118. `[]'
  119.      Go to end of heading.
  120.  
  121. `g <*movement command*>'
  122.      Search buffer for text delimited by movement command. The canonical
  123.      example is `gw' to search for the word under the cursor.  *Note
  124.      Improved Search::, for details.
  125.  
  126. `_'
  127.      Meta key when in Vi state.*Note Vi State::, for an explanation.
  128.  
  129. `C-g and C-]'
  130.      Quit and Abort Recursive edit. These may be necessary on occasion.
  131.      *Note Vi State::, for a reason.
  132.  
  133. `C-c g'
  134.      Hitting `C-c' followed by `g' will display the information on the
  135.      current buffer. This is the same as hitting  `C-g' in Vi, but, as
  136.      explained above, `C-g' is needed for other purposes in Emacs.
  137.  
  138. `C-c /'
  139.      Without a prefix argument, this command toggles
  140.      case-sensitive/case-insensitive search modes and plain
  141.      vanilla/regular expression search. With the prefix argument 1,
  142.      i.e., `1 C-c /', this toggles case-sensitivity; with the prefix
  143.      argument 2, toggles plain vanilla search and search using regular
  144.      expressions. *Note Viper Specials::, for alternative ways to invoke
  145.      this function.
  146.  
  147. `M-p and M-n'
  148.      In the Minibuffer, these commands navigate through the minibuffer
  149.      histories, such as the history of search strings, Ex commands, etc.
  150.  
  151. `C-c M-p and C-c M-n'
  152.      In Insert or Replace state, these commands let  the user peruse
  153.      the history of insertion strings used in previous insert or replace
  154.      commands. Try to hit `C-c M-p' or `C-c M-n' repeatedly and see what
  155.      happens. *Note Viper Specials::, for more.
  156.  
  157.      In Vi state, these commands let the user peruse the history of
  158.      Vi-style destructive commands, such as `dw', `J', `a', etc.  By
  159.      repeatedly typing `C-c M-p' or `C-c M-n' you will cycle Viper
  160.      through the recent history of Vi commands, displaying the commands
  161.      one by one. Once an appropriate command is found, it can be
  162.      executed by typing ``.''.
  163.  
  164.      Since typing `C-c M-p' is tedious, it is more convenient to bind an
  165.      appropriate function to a function key on the keyboard and use
  166.      that key.  *Note Viper Specials::, for details.
  167.  
  168. `Ex commands'
  169.      The commands `:args', `:next', `:pre' behave differently. `:pwd'
  170.      exists to get current directory.  The commands `:b' and `:B'
  171.      switch buffers around. *Note File and Buffer Handling::, for
  172.      details.  There are also the new commands `:RelatedFile' and
  173.      `PreviousRelatedFile' (which abbreviate to `R' and `P',
  174.      respectively. *Note Viper Specials::, for details.
  175.  
  176.    Apart from the new commands, many old commands have been enhanced.
  177. Most notably, Vi style macros are much more powerful in Viper than in
  178. Vi. *Note Vi Macros::, for details.
  179.  
  180. 
  181. File: viper.info,  Node: Useful Packages,  Prev: New Commands,  Up: Improvements over Vi
  182.  
  183. Useful Packages
  184. ===============
  185.  
  186.    Some Emacs packages are mentioned here as an aid to the new Viper
  187. user, to indicate what Viper is capable of.  A vast number comes with
  188. the standard Emacs distribution, and many more exist on the net and on
  189. the archives.
  190.  
  191.    This manual also mentions some Emacs features a new user should know
  192. about. The details of these are found in the GNU Emacs Manual.
  193.  
  194.    The features first. For details, look up the Emacs Manual.
  195.  
  196. `Make'
  197.      Makes and Compiles can be done from the editor. Error messages
  198.      will be parsed and you can move to the error lines.
  199.  
  200. `Shell'
  201.      You can talk to Shells from inside the editor. Your entire shell
  202.      session can be treated as a file.
  203.  
  204. `Mail'
  205.      Mail can be read from and sent within the editor. Several
  206.      sophisticated packages exist.
  207.  
  208. `Language Sensitive Editing'
  209.      Editing modes are written for most computer  languages in
  210.      existence. By controlling indentation, they catch punctuation
  211.      errors.
  212.  
  213.    The packages, below, represents a drop in the sea of special-purpose
  214. packages that come with standard distribution of Emacs 19.
  215.  
  216. `Transparent FTP'
  217.      `ange-ftp.el' can ftp from the editor to files on other machines
  218.      transparent to the user.
  219.  
  220. `RCS Interfaces'
  221.      `vc.el' for doing RCS commands from inside the editor
  222.  
  223. `Directory Editor'
  224.      `dired.el' for editing contents of directories and for navigating
  225.      in the file system.
  226.  
  227. `Syntactic Highlighting'
  228.      `hilit19.el' and `font-lock.el' for automatic highlighting various
  229.      parts of a buffer using different fonts and colors.
  230.  
  231. `Saving Emacs Configuration'
  232.      `desktop.el' for saving/restoring configuration on Emacs
  233.      exit/startup.
  234.  
  235. `Spell Checker'
  236.      `ispell.el' for spell checking the buffer, words, regions, etc.
  237.  
  238. `File and Buffer Comparison'
  239.      `ediff.el' for finding differences between files and for applying
  240.      patches.
  241.  
  242. Emacs Lisp archives exist on `archive.cis.ohio-state.edu' and
  243. `wuarchive.wustl.edu'
  244.  
  245. 
  246. File: viper.info,  Node: Customization,  Next: Commands,  Prev: Improvements over Vi,  Up: Top
  247.  
  248. Customization
  249. *************
  250.  
  251.    Customization can be done in 2 ways.
  252.  
  253.    * Elisp code in a `.vip' file in your home directory. Viper loads
  254.      `.vip' just before it does the binding for mode hooks. This is the
  255.      recommended method.
  256.  
  257.    * Elisp code in your `.emacs' file before and after the `(require
  258.      'viper)' line. This method is not recommended, unless you are know
  259.      what you are doing.
  260.  
  261. Emacs customization is done in Emacs Lisp. For the common cases,
  262. examples are provided that you can use directly.
  263.  
  264. * Menu:
  265.  
  266. * Rudimentary Changes::          Simple constant definitions.
  267. * Keybindings::                  Enabling Emacs Keys, Rebinding keys, etc.
  268. * Packages that Change Keymaps:: How to deal with such beasts.
  269. * Viper Specials::               Special Viper commands.
  270. * Vi Macros::                    How to do Vi style macros.
  271.  
  272. 
  273. File: viper.info,  Node: Rudimentary Changes,  Next: Keybindings,  Prev: Customization,  Up: Customization
  274.  
  275. Rudimentary Changes
  276. ===================
  277.  
  278.    An easy way to customize Viper is to change the values of constants
  279. used in Viper.  Here is the list of the constants used in Viper and
  280. their default values. The corresponding :se command is also indicated.
  281. (The symbols `t' and `nil' represent "true" and "false" in Lisp).
  282.  
  283.    Viper supports both the abbreviated Vi variable names and their full
  284. names. Variable completion is done on full names only. `TAB' and `SPC'
  285. complete variable names. Typing `=' will complete the name and then
  286. will prompt for a value, if applicable. For instance, `:se auSPC' will
  287. complete the command to `:set autoindent'; `:se taSPC' will complete
  288. the command and prompt further like this: `:set tabstop = '.  However,
  289. typing `:se tsSPC' will produce a "No match" message because `ts' is an
  290. abbreviation for `tabstop' and Viper supports completion on full names
  291. only. However, you can still hit `RET' or `=', which will complete the
  292. command like this: `:set ts = ' and Viper will be waiting for you to
  293. type a value for the tabstop variable.  To get the full list of Vi
  294. variables, type `:se SPC TAB'.
  295.  
  296. `vip-auto-indent nil'
  297. `:se ai (:se autoindent)'
  298.      If `t' then enable auto indentation.  by `o' or `O' command.
  299.  
  300. `vip-case-fold-search nil'
  301. `:se ic (:se ignorecase)'
  302.      If `t' search ignores cases.
  303.  
  304. `vip-re-search nil'
  305. `:se magic'
  306.      If `t' then search is reg-exp search, if `nil' then vanilla search.
  307.  
  308. `buffer-read-only'
  309. `:se ro (:se readonly)'
  310.      Set current buffer to read only. To change globally put
  311.      `(setq-default buffer-read-only t)' in your `.emacs' file.
  312.  
  313. `blink-matching-paren t'
  314. `:se sm (:se showmatch)'
  315.      Show matching parens by blinking cursor.
  316.  
  317. `tab-width t (default setting, via `setq-default')'
  318. `:se ts=value (:se tabstop=value)'
  319.      Set tab width to value for all buffers where the tab is not yet
  320.      set locally (see next), including the new buffers. Note that
  321.      typing `TAB' normally doesn't insert the tab, since this key is
  322.      usually bound to text-formatting function,
  323.      `indent-for-tab-command' (which facilitates programming and
  324.      document writing). Instead, the tab is inserted via the command
  325.      `vip-insert-tab', which is bound to `S-tab' (shift + tab).
  326.  
  327.      On some non-windowing terminals, Shift doesn't modify the `TAB'
  328.      key, so `S-tab' behaves as if it were `TAB'. In such a case, you
  329.      will have to bind `vip-insert-tab' to some other convenient key.
  330.  
  331. `tab-width t (local setting via `setq')'
  332. `:se tab-stop-local=value'
  333.      Like `:se ts', except that `tab-width' is set only for the current
  334.      buffer; it will have no effect on other buffers.
  335.  
  336. `vip-shift-width 8'
  337. `:se sw=value  (:se shiftwidth=value)'
  338.      The number of columns shifted by `>' and `<' commands.
  339.  
  340. `vip-search-wrap-around t'
  341. `:se ws (:se wrapscan)'
  342.      If `t', search wraps around the end/beginning of buffer.
  343.  
  344. `vip-tags-file-name "TAGS"'
  345.      The name of the file used as the tag table.
  346.  
  347. `vip-re-query-replace nil'
  348.      If `t', use reg-exp replace in query replace.
  349.  
  350. `vip-want-ctl-h-help nil'
  351.      If `t', `C-h' is bound to `help-command'; if `nil', it is bound to
  352.      `delete-backward-char'.
  353.  
  354. `vip-vi-style-in-minibuffer t'
  355.      If `t', Viper provides a high degree of compatibility with Vi
  356.      insert mode when you type text in the Minibuffer; if `nil', typing
  357.      in the Minibuffer feels like plain Emacs.
  358.  
  359. `vip-no-multiple-ESC t'
  360.      If you set this to `nil', you can use `ESC' as Meta in Vi state.
  361.      Normally, this is not necessary, since graphical displays have
  362.      separate Meta keys (usually on each side of the space bar). On a
  363.      dumb terminal, Viper sets this variable to `twice', which is
  364.      almost like `nil', except that double `ESC' beeps. This, too, lets
  365.      ESC to be used as a Meta.
  366.  
  367. `vip-keysequence-delay 140'
  368.      Escape sequences separated by this much delay are interpreted as
  369.      command, ignoring the special meaning of ESC in VI. The default is
  370.      suitable for most terminals. However, if your terminal is
  371.      extremely slow, you might want to increase this slightly. You will
  372.      know if your terminal is slow if the ESC key sequences emitted by
  373.      the arrow keys are interpreted as separately typed characters (and
  374.      thus the arrow keys won't work).  Making this value too large will
  375.      slow you down, so exercise restraint.
  376.  
  377. `vip-ex-style-motion t'
  378.      Set this to `nil', if you want `l,h' to cross lines, etc. *Note
  379.      Movement and Markers::, for more info.
  380.  
  381. `vip-ex-style-editing-in-insert t'
  382.      Set this to to `nil', if you want `ESC' to not move back and `C-h'
  383.      to not stop at the beginning of a line in Insert state.
  384.  
  385. `vip-always t'
  386.      Leave it to Viper to decide when a buffer must be brought up in Vi
  387.      state, Insert state, or Emacs state. This heuristics works well in
  388.      virtually all cases.  This option must be set before Viper is
  389.      loaded or in the `.vip' file.
  390.  
  391. `vip-custom-file-name "~/.vip"'
  392.      Change this if you want. Must be set in `.emacs' (not `.vip'!)
  393.      before Viper is loaded. Note that you have to set it as a string
  394.      inside double quotes.
  395.  
  396. `vip-spell-function 'ispell-region'
  397.      Function used by the command `#c<move>' to spell.
  398.  
  399. `ex-find-file-shell "csh"'
  400.      Shell used to interpret filenames. If you have problems with Csh,
  401.      change to something else. Note that you have to set it as a string
  402.      inside double quotes.
  403.  
  404. `ex-cycle-other-window t'
  405.      If `t', `:n' and `:b' will cycle through files in another window,
  406.      if one exists.
  407.  
  408. `ex-cycle-through-non-files nil'
  409.      `:n' does not normally cycle through buffers. Set this to get
  410.      buffers also.
  411.  
  412. `vip-automatic-iso-accents nil'
  413.      If `t', ISO accents will be turned on in insert/replace Viper
  414.      states and turned off in Vi state. This is useful for editing text
  415.      in European languages.
  416.  
  417. `vip-want-emacs-keys-in-insert'
  418.      This is set to `nil' for user levels 1 and 2 and to `t' for user
  419.      levels 3 and 4. Users who specify level 5 are allowed to set this
  420.      variable as they please (the default for this level is `t'). If
  421.      set to `nil', complete Vi compatibility is provided in Insert
  422.      state. This is really not recommended, as this precludes you from
  423.      using language-specific features provided by the major modes.
  424.  
  425. `vip-want-emacs-keys-in-vi'
  426.      This is set to `nil' for user level 1 and to `t' for user levels
  427.      2-4.  At level 5, users are allowed to set this variable as they
  428.      please (the default for this level is `t').  If set to `nil',
  429.      complete Vi compatibility is provided in Vi command state. Setting
  430.      this to `nil' is really a bad idea, unless you are a novice, as
  431.      this precludes the use of language-specific features provided by
  432.      the major modes.
  433.  
  434. `vip-keep-point-on-repeat t'
  435.      If `t', point is not moved when the user repeats the previous
  436.      command by typing `.'  This is very useful for doing repeated
  437.      changes with the `.' key.
  438.  
  439. `vip-repeat-from-history-key 'f12'
  440.      Prefix key used to invoke the macros `f12 1' and `f12 2' that
  441.      repeat the second-last and the third-last destructive command.
  442.      Both these macros are bound (as Viper macros) to
  443.      `vip-repeat-from-history', which checks the second key by which it
  444.      is invoked to see which of the previous commands to invoke. Viper
  445.      binds `f12 1' and `f12 2' only, but the user can bind more in
  446.      `~/.vip'. *Note Vi Macros::, for how to do this.
  447.  
  448. `vip-keep-point-on-undo nil'
  449.      If `t', Viper tries to not move point when undoing commands.
  450.      Instead, it will briefly move the cursor to the place where change
  451.      has taken place. However, if the undone piece of text is not seen
  452.      in window, then point will be moved to the place where the change
  453.      took place.  Set it to `t' and see if you like it better.
  454.  
  455. `vip-delete-backwards-in-replace nil'
  456.      If `t', DEL key will delete characters while moving the cursor
  457.      backwards.  If `nil', the cursor will move backwards without
  458.      deleting anything.
  459.  
  460. `vip-replace-overlay-face 'vip-replace-overlay-face'
  461.      On a graphical display, Viper highlights replacement regions
  462.      instead of putting a `$' at the end. This variable controls the so
  463.      called "face" used to highlight the region.
  464.  
  465.      By default, `vip-replace-overlay-face' underlines the replacement
  466.      on monochrome displays and highlights it with color on  color
  467.      displays.  If you know something about Emacs faces and don't like
  468.      how Viper highlights replacement regions, you can change this
  469.      variable to specify a new face name. (Emacs faces are described in
  470.      the Emacs Lisp reference.) On a color display, the following
  471.      customization method is usually most effective:
  472.           (set-face-foreground vip-replace-overlay-face "DarkSlateBlue")
  473.           (set-face-background vip-replace-overlay-face "yellow")
  474.      For a complete list of colors available to you, evaluate the
  475.      expression `(x-defined-colors)'. (Type it in the buffer `*scratch*'
  476.      and then hit the `C-j' key.
  477.  
  478. `vip-replace-overlay-cursor-color  "Red"'
  479.      Cursor color when it is inside the replacement region.  This has
  480.      effect only on color displays and only when Emacs runs as an X
  481.      application.
  482.  
  483. `vip-replace-region-end-delimiter "$"'
  484.      A string used to mark the end of replacement regions.  It is used
  485.      only with TTYs or if `vip-use-replace-region-delimiters' is
  486.      non-nil.
  487.  
  488. `vip-replace-region-start-delimiter  ""'
  489.      A string used to mark the beginning of replacement regions.  It is
  490.      used only with TTYs or if `vip-use-replace-region-delimiters' is
  491.      non-nil.
  492.  
  493. `vip-use-replace-region-delimiters'
  494.      If non-nil, Viper will always use
  495.      `vip-replace-region-end-delimiter' and
  496.      `vip-replace-region-start-delimiter' to delimit replacement
  497.      regions, even on color displays (where this is unnecessary). By
  498.      default, this variable is non-nil only on TTYs or monochrome
  499.      displays.
  500.  
  501. `vip-toggle-key "\C-z"'
  502.      Specifies the key used to switch from Emacs to Vi and back.  Must
  503.      be set in `.vip' or prior to loading Viper. This variable can't be
  504.      changed interactively after Viper is loaded.
  505.  
  506. `vip-ESC-key "\e"'
  507.      Specifies the key used to escape from Insert/Replace states to Vi.
  508.      Must be set in `.vip' or prior to loading Viper. This variable
  509.      cannot be changed interactively after Viper is loaded.
  510.  
  511. `vip-buffer-search-char nil'
  512.      Key used for buffer search. *Note Viper Specials::, for details.
  513.  
  514. `vip-surrounding-word-function 'vip-surrounding-word'
  515.      The value of this variable is a function name that is used to
  516.      determine what constitutes a word clicked upon by the mouse. This
  517.      is used by mouse search and insert.
  518.  
  519. `vip-search-face 'vip-search-face'
  520.      Variable that controls how search patterns are highlighted when
  521.      they are found.
  522.  
  523. `vip-vi-state-hooks nil'
  524.      List of parameterless functions to be run just after entering the
  525.      Vi command state.
  526.  
  527. `vip-insert-state-hooks nil'
  528.      Same for Insert state. This hook is also run after entering
  529.      Replace state.
  530.  
  531. `vip-replace-state-hooks  nil'
  532.      List of (parameterless) functions called just after entering
  533.      Replace state (and after all `vip-insert-state-hooks').
  534.  
  535. `vip-emacs-state-hooks nil'
  536.      List of (parameterless) functions called just after switching from
  537.      Vi state to Emacs state.
  538.  
  539. `vip-load-hooks nil'
  540.      List of (parameterless) functions called just after loading Viper.
  541.      This is the last chance to do customization before Viper is up and
  542.      running.
  543.  
  544. You can reset some of these constants in Viper with the Ex command
  545. `:set' (when so indicated in the table).  Or you can include a line
  546. like this in your `.vip' file:
  547.      (setq vip-case-fold-search t)
  548.  
  549. 
  550. File: viper.info,  Node: Keybindings,  Next: Packages that Change Keymaps,  Prev: Rudimentary Changes,  Up: Customization
  551.  
  552. Keybindings
  553. ===========
  554.  
  555.    Viper lets you define hot keys, i.e., you can associate keyboard keys
  556. such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may
  557. already exist or that you will write). Each key has a "preferred form"
  558. in Emacs. For instance, the Up key's preferred form is [up], the Help
  559. key's preferred form is [help], and the Undo key has the preferred form
  560. [f14].  You can find out the preferred form of a key by typing `M-x
  561. describe-key-briefly' and then typing the key you want to know about.
  562.  
  563.    Under X Windows, every keyboard key emits its preferred form, so you
  564. can just type
  565.  
  566.      (global-set-key [f11] 'calendar)                        ; L1, Stop
  567.      (global-set-key [f14] 'undo)                            ; L4, Undo
  568.  
  569. to bind L1 so it will invoke the Emacs Calendar and to bind L4 so it
  570. will undo changes.  However, on a dumb terminal or in an Xterm window,
  571. even the standard arrow keys may not emit the right signals for Emacs
  572. to understand. To let Emacs know about those keys, you will have to
  573. find out which key sequences they emit by typing `C-q' and then the key
  574. (you should switch to Emacs state first). Then you can bind those
  575. sequences to their preferred forms using `function-key-map' as follows:
  576.  
  577.      (cond ((string= (getenv "TERM") "xterm")
  578.             (define-key function-key-map "\e[192z" [f11])    ; L1
  579.             (define-key function-key-map "\e[195z" [f14])    ; L4, Undo
  580.  
  581.    The above illustrates how to do this for Xterm. On VT100, you would
  582. have to replace "xterm" with "vt100" and also change the key sequences
  583. (the same key may emit different sequences on different types of
  584. terminals).
  585.  
  586.    The above keys are global, so they are overwritten by the local maps
  587. defined by the major modes and by Viper itself. Therefore, if you wish
  588. to change a binding set by a major mode or by Viper, read this.
  589.  
  590.    Viper users who wish to specify their own key bindings should be
  591. concerned only with the following three keymaps:
  592. `vip-vi-global-user-map' for Vi state commands,
  593. `vip-insert-global-user-map' for Insert state commands, and
  594. `vip-emacs-global-user-map' for Emacs state commands (note: customized
  595. bindings for Emacs state made to `vip-emacs-global-user-map' are *not*
  596. inherited by Insert state).
  597.  
  598.    For more information on Viper keymaps, see the header of the file
  599. `viper.el'.  If you wish to change a Viper binding, you can use the
  600. `define-key' command, to modify `vip-vi-global-user-map',
  601. `vip-insert-global-user-map', and `vip-emacs-global-user-map', as
  602. explained below. Each of these key maps affects the corresponding Viper
  603. state.  The keymap `vip-vi-global-user-map' also affects Viper's
  604. Replace state.
  605.  
  606. If you want to bind a key, say `C-v', to the function that scrolls page
  607. down and to make `0' display information on the current buffer, putting
  608. this in `.vip' will do the trick in Vi state:
  609.      (define-key vip-vi-global-user-map "\C-v" 'scroll-down)
  610.  
  611. To set a key globally,
  612.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  613.      (define-key vip-vi-global-user-map "0" 'vip-info-on-file)
  614.  
  615. Note, however, that this binding may be overwritten by other keymaps,
  616. since the global keymap has the lowest priority.  To make sure that
  617. nothing will override a binding in Emacs state, you can write this:
  618.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  619.  
  620. To customize the binding for `C-h' in Insert state:
  621.      (define-key vip-insert-global-user-map "\C-h" 'my-del-backwards-function)
  622.  
  623. Each Emacs command key calls some lisp function. If you have enabled the
  624. Help, (*Note Rudimentary Changes::) `C-h k' will show you the function
  625. for each specific key; `C-h b' will show all bindings, and `C-h m' will
  626. provide information on the major mode in effect. If Help is not
  627. enabled, you can still get help in Vi state by prefixing the above
  628. commands with `\', e.g., `\ C-h k' (or you can use the Help menu in the
  629. menu bar, if Emacs runs under X Windows).
  630.  
  631.    Viper users can also change bindings on a per major mode basis.  As
  632. with global bindings, this can be done separately for each of the three
  633. main Viper states.  To this end, Viper provides the function
  634. `vip-modify-major-mode'.
  635.  
  636.    To modify keys in Emacs state for `my-favorite-major-mode', the user
  637. needs to create a sparse keymap, say, `my-fancy-map', bind whatever
  638. keys necessary in that keymap, and put
  639.  
  640.      (vip-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
  641.  
  642. in `~/.vip'. To do the same in Vi and Insert states, one should use
  643. `vi-state' and `insert-state'. Changes in Insert state are also in
  644. effect in Replace state.  For instance, suppose that the user wants to
  645. use `dd' in Vi state under Dired mode to delete files, `u' to unmark
  646. files, etc. The following code in `~/.vip' will then do the job:
  647.  
  648.      (setq my-dired-modifier-map (make-sparse-keymap))
  649.      (define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
  650.      (define-key my-dired-modifier-map "u" 'dired-unmark)
  651.      (vip-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
  652.  
  653.    A Vi purist may want to modify Emacs state under Dired mode so that
  654. `k', `l', etc., will move around in directory buffers, as in Vi.
  655. Although this is not recommended, as these keys are bound to useful
  656. Dired functions, the trick can be accomplished via the following code:
  657.  
  658.      (setq my-dired-vi-purist-map (make-sparse-keymap))
  659.      (define-key my-dired-vi-purist-map "k" 'vip-previous-line)
  660.      (define-key my-dired-vi-purist-map "l" 'vip-forward-char)
  661.      (vip-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
  662.  
  663.    Similar effect can be achieved by defining Vi keyboard macros using
  664. the Ex commands `:map' and `:map!'. The difference is that multi-key Vi
  665. macros do not override the keys they are bound to, unless these keys are
  666. typed in quick succession. So, with macros, one can use the normal keys
  667. alongside with the macros. If per-mode modifications are needed, the
  668. user can try both ways and see which one is more convenient.  *Note Vi
  669. Macros::, for details.
  670.  
  671.    Note: in major modes that come up in *Emacs state* by default, the
  672. aforesaid modifications may not take place immediately (but only after
  673. the buffer switches to some other Viper state and then back to Emacs
  674. state).  To avoid this, one should add `vip-change-state-to-emacs' to an
  675. appropriate hook of that major mode. (Check the function
  676. `vip-set-hooks' in `viper.el' for examples.)  However, if you have set
  677. `vip-always' to `t', chances are that you won't need to perform the
  678. above procedure, because Viper will take care of most useful defaults.
  679.  
  680.    Finally, Viper has a facility that lets the user define per-buffer
  681. bindings, i.e., bindings that are in effect in some specific buffers
  682. only. Unlike per-mode bindings described above, per-buffer bindings can
  683. be defined based on considerations other than the major mode.  This is
  684. done via the function `vip-add-local-keys', which lets one specify
  685. bindings that should be in effect in the current buffer only and for a
  686. specific Viper state. For instance,
  687.      (vip-add-local-keys 'vi-state '(("ZZ" . TeX-command-master)
  688.                                      ("ZQ" . vip-save-kill-buffer)))
  689.  
  690. redefines `ZZ' to invoke `TeX-command-master' in `vi-state' and `ZQ' to
  691. save-then-kill the current buffer. These bindings take effect only in
  692. the buffer where this command is executed. The typical use of this
  693. function is to execute the above expression from within a function that
  694. is included in a hook to some major mode. For instance, the above
  695. expression could be called from a function, `my-tex-init', which may be
  696. added to `tex-mode-hook' as follows:
  697.      (add-hook 'tex-mode-hook 'my-tex-init)
  698.  
  699. When TeX mode starts, the hook is executed and the above Lisp
  700. expression is evaluated. Then, the bindings for `ZZ' and `ZQ' are
  701. changed in Vi command mode for all buffers in TeX mode.
  702.  
  703.    Another useful application is to bind `ZZ' to `send-mail' in the
  704. Mail mode buffers (the specifics of this depend on which mail package
  705. you are using, `rmail', `mh-e', `vm', etc.  For instance, here is how
  706. to do this for `mh-e', the Emacs interface to MH:
  707.      (defun mh-add-vi-keys ()
  708.        "Set up ZZ for MH-e and XMH."
  709.        (vip-add-local-keys 'vi-state '(("ZZ" . mh-send-letter))))
  710.      (add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
  711.  
  712.    You can also use `vip-add-local-keys' to set per buffer bindings in
  713. Insert state and Emacs state by passing as a parameter the symbols
  714. `'insert-state' and `'emacs-state', respectively.  As with global
  715. bindings, customized local bindings done to Emacs state are not
  716. inherited by Insert state.
  717.  
  718.    So much about Viper-specific bindings.  *Note Customization:
  719. (emacs)Customization, and the Emacs quick reference card for the
  720. general info on key bindings in Emacs.
  721.  
  722. 
  723. File: viper.info,  Node: Packages that Change Keymaps,  Next: Viper Specials,  Prev: Keybindings,  Up: Customization
  724.  
  725. Packages that Change Keymaps
  726. ----------------------------
  727.  
  728.    Viper is designed to coexist with all major and minor modes of
  729. Emacs. This means that bindings set by those modes are generally
  730. available with Viper (unless you explicitly prohibit them by setting
  731. `vip-want-emacs-keys-in-vi' and `vip-want-emacs-keys-in-insert' to
  732. `nil').  If `vip-always' is set to `t', Viper will try to bring each
  733. buffer in the a Viper state that is most appropriate for that buffer.
  734. Usually, this would be the Vi state, but sometimes it could be the
  735. Insert state or the Emacs state.
  736.  
  737.    Some major mode bindings will necessarily be overwritten by Viper.
  738. Indeed, in Vi state, most of the 1-character keys are used for Vi-style
  739. editing.  This usually causes no problems because most packages
  740. designed for editing files typically do not bind such keys. Instead,
  741. they use key sequences that start with `C-x' and `C-c'. This is why it
  742. was so important for us to free up `C-x' and `C-c'.  It is common for
  743. language-specific major modes to bind `TAB' and `LFD' (the line feed)
  744. keys to various formatting functions. This is extremely useful, but may
  745. require some getting used to for a Vi user. If you decide that this
  746. feature is not for you, you can re-bind these keys as explained earlier
  747. (*Note Customization::).
  748.  
  749.    Binding for `TAB' is one of the most unusual aspects of Viper for
  750. many novice users.  In Emacs, `TAB' is used to format text and
  751. programs, and is extremely useful. For instance, hitting `TAB' causes
  752. the current line to be re-indented in accordance with the context.  In
  753. programming, this is very important, since improper automatic
  754. indentation would immediately alert the programmer to a possible error.
  755. For instance, if a `)' or a `"' is missing somewhere above the current
  756. line, `TAB' is likely to mis-indent the line.
  757.  
  758.    For this reason, Viper doesn't change the standard Emacs binding of
  759. `TAB', thereby sacrificing Vi compatibility (except for users at level
  760. 1). Instead, in Viper, the key `S-tab' (shift+ tab) is chosen to
  761. emulate Vi's `TAB'.
  762.  
  763.    We should note that on some non-windowing terminals, Shift doesn't
  764. modify the `TAB' key, so `S-tab' behaves as if it were `TAB'. In such a
  765. case, you will have to bind `vip-insert-tab' to some other convenient
  766. key.
  767.  
  768.    Some packages, notably Dired, Gnus, Info, etc., attach special
  769. meaning to common keys like `SPC', `x', `d', `v', and others. This
  770. means that Vi command state is inappropriate for working with these
  771. packages. Fortunately, these modes operate on read-only buffers and are
  772. designed not for editing files, but for special-purpose browsing,
  773. reading news, mail, etc., and Vi commands are meaningless in these
  774. situations. For this reason, Viper doesn't force Vi state on such major
  775. modes.  Rather, it brings them in Emacs state. You can switch to Vi
  776. state by typing `C-z' if, for instance, you want to do Vi-style search
  777. in a buffer (although, usually, incremental search, which is bound to
  778. `C-s', is sufficient in these situations). But you should then switch
  779. back to Emacs state if you plan to continue using these major modes
  780. productively. You can also switch to Vi temporarily, to execute one
  781. 1-character command. This is done by typing `M-C-z' (or `ESC C-z').
  782. This facility cannot execute several complex Vi commands, such as `dw',
  783. `de', etc.
  784.  
  785.    It is also possible to harness some major modes, even though they
  786. may bind common keys to specialized commands. Harnessing can make sense
  787. for modes that bind only a small number of common keys.  For instance,
  788. if `vip-always' is set to `t' in your `~/.vip' file, Viper will harness
  789. the Shell mode by changing the bindings for `C-m' and `C-d' using
  790. `vip-add-local-keys' described in section on customization (*Note
  791. Customization::). In general, there is no single recipe for harnessing
  792. modes. It can be as simple as adding the function `viper-mode' to a
  793. hook associated with the mode, or it can be more complex, as in the
  794. case of Shell mode and Emerge. Take a look at `vip-set-hooks' function
  795. for some examples.
  796.  
  797.    Conversely, it may be the case that most of the major modes harnessed
  798. by `vip-set-hooks' function fit your working style, except one or two
  799. cases. In this case, you may still be able to set `vip-always' to `t'
  800. and then remove a hook that forces Vi command state. For instance, to
  801. unharness `lisp-interaction-mode', you can put the following line in
  802. your `.emacs' (not `.vip'!) file after `(require 'viper)':
  803.      (remove-hook 'lisp-interaction-mode-hook 'viper-mode)
  804.  
  805.    In some rare cases, some minor modes may override certain essential
  806. bindings in Vi command state.  This is not really catastrophic because
  807. this may happen only in the beginning, when the minor mode kicks in.
  808. Typing `M-x viper-mode' will correct the situation.  Viper knows about
  809. several such minor modes and takes care of them, so that the above trick
  810. is usually not necessary.  If you find that some minor mode, e.g.,
  811. `nasty-mode.el' interferes with Viper, putting the following in `.vip'
  812. should fix the problem:
  813.      (vip-harness-minor-mode "nasty-mode")
  814.  
  815. The argument to `vip-harness-minor-mode' is the name of the file for the
  816. offending minor mode with the suffixes `.el' and `.elc' removed.
  817.  
  818.    It may be tricky, however, to find out which minor mode is at fault.
  819. The only guidance here is to look into the file that defines the minor
  820. mode you are suspecting, say `nasty-mode.el', and see if it has a
  821. variable called `nasty-mode-map'. Then check if there is a statement of
  822. the form
  823.      (define-key nasty-mode-map key function)
  824.  
  825. that binds the misbehaving keys. If so, use the above line to harness
  826. `nasty-mode'. If your suspicion is wrong, no harm is done if you
  827. harness a minor mode that doesn't need to be harnessed.
  828.  
  829.